﻿@model List<SmallJob.Model.MMessage>
@{
    var tablename = "TableComplaint";
    var numbercolumn = 5;
    var colsname = new[] { "Sender ID", "Phone Sender", "Status", "Date", "Order", "Content" };
    var curaction = "Index";
    var curcontroller = "Order";
    var configaction = new { details = "Details", del = "Lock", create = "Create", undel = "UnLock" };
    var configtext = new { details = "Details", del = "Lock", create = "Create", undel = "UnLock" };
    var isfilter = !(ViewData["filter"] == null);
}
<br />
<input type="text" name="search" value="@(isfilter ? ViewData["filter"] : "")" id="inputsearch" />
Search Here, Type and Enter
<div class="div-parent">

    <table class="table table-hover sort">
        <thead>
            <tr>
                @for (int i = 0; i < numbercolumn; i++)
                {
                    <th>@colsname[i]
                        <span style="float: right;"><i class="icon-sort"></i></span>
                    </th>
                }
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model)
            {
                <tr>
                    <td>
                        @item.SenderID
                    </td>
                    <td>
                        @item.Info.Phone
                    </td>
                    <td>
                        @(item.IsRead ? "Read" : "New")
                    </td>
                    <td>
                        @item.Date.ToString("dd/MM/yyyy hh:mm tt")
                    </td>
                    <td>
                        @item.ParentID
                    </td>
                    <td>
                        <a href="#" onclick="detail('@item.Id');">@SmallJob.Services.Code.UserUtility.ShortString(item.Content, "50") </a>
                    </td>
                </tr>
            }
        </tbody>

    </table>

    <div class="pagination">
        <ul>
            @{
                var total = Convert.ToInt32(ViewData["total"]);
                var curpage = Convert.ToInt32(ViewData["curpage"]);
                if (curpage > 1)
                {
                <li><a href="/@curcontroller/@curaction/pages/@(curpage - 1)/filter/@(isfilter ? ViewData["filter"] : "")">Prev</a></li>
                }
                for (int i = 1; i <= total; i++)
                {
                    if (i != curpage)
                    {
                <li><a href="/@curcontroller/@curaction/pages/@(i)/filter/@(isfilter ? ViewData["filter"] : "")">@i</a></li>
                    }
                    else
                    {
                <li><a href="/@curcontroller/@curaction/pages/@(i)/filter/@(isfilter ? ViewData["filter"] : "")"><strong>@i</strong></a></li>
                    }

                }
                if (curpage < total)
                {
                <li><a href="/@curcontroller/@curaction/pages/@(curpage + 1)/filter/@(isfilter ? ViewData["filter"] : "")">Next</a></li>
                }
            }


        </ul>
    </div>
</div>
<div id="show-detail" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
    <div class="modal-body" style="max-height: none" id="div-content-detail"></div>
</div>
<script src="@Url.Content("~/Content/js/jquery.tablesorter.min.js")"></script>
<script>
    //table sort
    $(function () {
        $("table.sort").tablesorter({ sortList: [[0, 0]] });
    });
    $("table").bind("sortStart", function () {
    }).bind("sortEnd", function () {
        $('th.header').each(function () {
            if ($(this).hasClass('headerSortDown')) {
                $(this).find('.icon-sort').addClass('icon-hand-up');
                $(this).find('.icon-sort').removeClass('icon-hand-down');

            }
            if ($(this).hasClass('headerSortUp')) {
                $(this).find('.icon-sort').addClass('icon-hand-down');
                $(this).find('.icon-sort').removeClass('icon-hand-up');
            }
            if (!$(this).hasClass('headerSortDown') && !$(this).hasClass('headerSortUp')) {
                $(this).find('.icon-sort').removeClass('icon-hand-down');
                $(this).find('.icon-sort').removeClass('icon-hand-up');
            }
        });
    });
    //del and undel ajax
    function del(source, id) {
        $.ajax({
            type: "POST",
            url: '@Url.Action(configaction.del, curcontroller)',
            data: { id: id },
            success: function (data) {
                if (data == true) {
                    $(source).text('@configtext.undel');
                    $(source).attr('onClick', 'undel(this,' + id + ')');
                } else {
                }
            }
        });
    }
    function undel(source, id) {
        $.ajax({
            type: "POST",
            url: '@Url.Action(@configaction.undel, curcontroller)',
            data: { id: id },
            success: function (data) {
                if (data == true) {
                    $(source).text('@configtext.del');
                    $(source).attr('onClick', 'del(this,' + id + ')');
                } else {
                }
            }
        });
    }
    $(document).ready(function () {
        $('#inputsearch').change(function () {
            var filter = $(this).val();
            $.ajax({
                type: "POST",
                url: '@Url.Action(@tablename, curcontroller)',
                data: { target: 1, page: 1, pagesize: 1, filter: filter },
                success: function (data) {
                    if (data != null) {
                        var getdata = $(data).filter('.div-parent');
                        $('.div-parent').html(getdata.html());
                    } else {
                    }
                }
            });
        });
    });
    function detail(id) {
        $.post('@Url.Action("DetailComplaint", "Order")', { id: id }, function (data) {
            $('#div-content-detail').html(data);
            $('#show-detail').modal({ show: true });
        });
    }
</script>
